import {useState, useEffect} from 'react';
import Http from '@/utils/http';

export default (
  {
    url,
    method = 'post',
    headers,
    body = {},
    watch = []
  }
) => {
  const [result, setResult] = useState();
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    Http({
      url,
      method,
      headers,
      body,
      setResult,
      setLoading
    });
  }, watch);

  return [result, loading];
}
